﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Common;

namespace School.Admin.Admin
{
    public partial class EditType : CheckPower
    {
        #region 传递参数
        /// <summary>
        /// ID
        /// </summary>
        public int ID
        {
            get
            {
                if (Request.QueryString["id"] == null || Request.QueryString["id"] == "")
                {
                    return 0;
                }
                return int.Parse(Request.QueryString["id"].ToString());
            }
        }
        #endregion
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (ID > 0)
                {
                    Model.UserType u = new BLL.UserType().GetModel(ID);
                    txtName.Text = u.TypeName;
                    TextBox1.Text = u.Description;
                    RadioButtonList1.SelectedValue = u.State.ToString();
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (ID > 0)
            {
                Model.UserType u = new BLL.UserType().GetModel(ID);
                u.TypeName = txtName.Text.Trim();
                u.Description = TextBox1.Text;
                u.State = int.Parse(RadioButtonList1.SelectedValue);
                new BLL.UserType().Update(u);
                ScriptHelper.Alert("修改成功！");
            }
            else
            {
                Model.UserType u = new Model.UserType();
                u.TypeName = txtName.Text.Trim();
                u.Description = TextBox1.Text;
                u.State = int.Parse(RadioButtonList1.SelectedValue);
                new BLL.UserType().Add(u);
                ScriptHelper.AlertRedirect("增加成功！", "UserType.aspx");
            }
        }

    }
}